<div class="links clearfix">
    <ul class="links-menu">
        <li>
            <a href="{% url 'main:category' 0 %}"
               class="{% if request.resolver_match.url_name == 'category' and request.resolver_match.kwargs.pk == 0 %}active{% endif %}">
                все
            </a>
        </li>

        {% for item in categories %}
            <li>
                <a href="{% url 'main:category' item.pk %}"
                   class="{% if request.resolver_match.url_name == 'category' and request.resolver_match.kwargs.pk == item.pk %}active{% endif %}">
                    {{ item.name }}
                </a>
            </li>
        {% endfor %}
    </ul>
</div>